#!/bin/bash
# 视频播放器卸载脚本
set -e

# ===== 配置区 =====
APP_NAME="video"
# ==================

# 检查是否以root运行
if [ "$(id -u)" -ne 0 ]; then
    echo "请使用sudo运行此脚本或切换到root用户"
    exit 1
fi

# 系统路径
INSTALL_DIR="/usr/local/bin"
DESKTOP_FILE="/usr/share/applications/$APP_NAME.desktop"

# 卸载步骤
echo "[1/4] 移除可执行文件..."
[ -f "$INSTALL_DIR/$APP_NAME" ] && rm -v "$INSTALL_DIR/$APP_NAME"

echo "[2/4] 移除桌面菜单项..."
[ -f "$DESKTOP_FILE" ] && rm -v "$DESKTOP_FILE"

echo "[3/4] 移除图标和缓存..."
ICON_SIZES=(16 22 24 32 48 64 128 256 512)
for size in "${ICON_SIZES[@]}"; do
    icon_path="/usr/share/icons/hicolor/${size}x${size}/apps/$APP_NAME.png"
    [ -f "$icon_path" ] && rm -v "$icon_path"
done
# 清理所有图标缓存
find /usr/share/icons/hicolor -name "icon-theme.cache" -delete

echo "[4/4] 刷新系统配置..."
update-desktop-database
gtk-update-icon-cache --force /usr/share/icons/hicolor
update-mime-database /usr/share/mime

echo -e "\n\e[32m卸载完成！\e[0m"
echo "建议重启系统以完全清除图标缓存"
